package com.ossjk.qlh.minapp.OrderID;

import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.stereotype.Component;

import javax.rmi.CORBA.Util;
import java.util.concurrent.TimeUnit;

@Component
public class RedesOrderService implements IOrderService {


    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public String generateOrderNum(OrderType orderType) {
        RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(OrderUtil.generateKey(orderType), redisTemplate.getConnectionFactory());
        redisAtomicInteger.expire(orderType.getDuration(), TimeUnit.MILLISECONDS);
        return OrderUtil.generateNum(redisAtomicInteger.getAndIncrement(), orderType);
    }
}
